export const KEY_PUBLIC: string = 'PUBLICKEY';
export const KEY_CRYPTO: string = 'CRYPTO';
export const KEY_IV: string = 'IV';
export const KEY_TOKEN: string = 'token';

export const TOKEN_PREFIX = 'bearer ';

export function getItem(key: string): string {
  if (isEmpty(key)) return '';

  const item = window.sessionStorage.getItem(key);
  if (!isEmpty(item)) return item!;
  else return '';
}

export function setItem(key: string, val: string): boolean {
  if (isEmpty(key) || isEmpty(val)) return false;

  window.sessionStorage.setItem(key, val);
  return true;
}

export function removeItem(key: string): boolean {
  if (isEmpty(key)) return false;
  window.sessionStorage.removeItem(key);
  return true;
}

export function clear(): void {
  window.sessionStorage.clear();
}

export function isEmpty(s: string | null): boolean {
  if (s === null || s === '' || s.trim().length === 0 || s === 'undefined' || s === undefined)
    return true;
  else return false;
}
